package com.distributer.product.request;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.distributer.product.model.DistributerProduct;
import com.distributer.product.service.DistributerProductService;

/**
 * 缓存刷新请求
 * @author Administrator
 *
 */
public class ProductRefreshRequest implements Request{

	private static final Logger LOGGER = LoggerFactory.getLogger(ProductRefreshRequest.class);
	
	private final DistributerProduct distributerProduct;
	
	private final DistributerProductService distributerProductService;
	
	public ProductRefreshRequest(DistributerProduct distributerProduct, DistributerProductService distributerProductService) {
		this.distributerProduct = distributerProduct;
		this.distributerProductService = distributerProductService;
	}

	@Override
	public void process() {
		//查询产品
		DistributerProduct productFromDb = distributerProductService.findDistributerProductByJbProductCode(distributerProduct.getProductCode());
		//刷新缓存
		distributerProductService.cacheRefresh(productFromDb);
		LOGGER.info("产品编码： "+distributerProduct.getProductCode()+"缓存刷新成功！");
	}
	
	@Override
	public String getJbProductCode() {
		return this.distributerProduct.getProductCode();
	}

}
